<template>
  <div class="detail">
    <c-title :hide="false" :text="text"></c-title>
    <header class="header">
      <div>
        <van-image round width="2.5rem" height="2.5rem" :src="form.avatar_image" />
        <div class="office-status" v-if="lawyer_type == 'office'">{{form.status==1?'经营':'休息'}}</div>
      </div>
      <div class="header-info">
        <div class="header-name">{{lawyerInfo.name}} </div>
        <ul class="header-domain-wrapper" v-if="lawyer_type == 'lawyer'">
          <li class="header-domain-item" v-for="item in domain_nickName" :key="item.id">{{item.title}}</li>
        </ul>
        <div class="header-num" v-if="lawyer_type == 'lawyer'">咨询次数：{{lawyerInfo.consult_time}}</div>
        <div class="header-tel" v-if="lawyer_type == 'office'">电话：{{lawyerInfo.tel}}</div>
        <div class="header-address" v-if="lawyer_type == 'office'">地址：{{address}}</div>
      </div>
    </header>
    <main class="main">
      <div class="desc" v-if="lawyer_type == 'lawyer'">
        <div class="title">律师基本信息</div>
        <ul class="desc-content">
          <li class="basic-info">
            <span class="key">性别：</span>
            <span class="value">{{lawyerInfo.gender=="1"?'男':'女'}}</span>
          </li>
          <li class="basic-info">
            <span class="key">职业年限：</span>
            <span class="value">{{lawyerInfo.year}}年</span>
          </li>
          <li class="basic-info">
            <span class="key">职称：</span>
            <span class="value">{{lawyerInfo.title}}</span>
          </li>
          <li class="basic-info" @click="link">
            <span class="key">所属律所：</span>
            <span class="value" >{{lawfirmName}}</span>
          </li>
          <li class="basic-info">
            <span class="key">服务区域：</span>
            <span class="value">{{lawyerInfo.show_address}}</span>
          </li>
          <li class="basic-info">
            <span class="key">执业证号：</span>
            <span class="value">{{lawyerInfo.number}}</span>
          </li>
          <li class="basic-info">
            <div class="key photo">执业照片：</div>
            <van-image width="7.5rem" height="7.5rem" :src="lawyerInfo.number_thumb_image" />
          </li>
        </ul>
      </div>
      <div class="desc">
        <div class="title">简介</div>
        <div class="desc-content">{{lawyerInfo.introduction}}</div>
      </div>
      <template  v-if="lawyer_type == 'office'">
      <div class="desc">
        <div class="title">资质</div>
        <van-image width="7.5rem" height="7.5rem" :src="lawyerInfo.thumb_image"/>
      </div>
      <div class="lawyer">
        <div class="title">律师</div>
        <keep-alive>
          <lawyerPlatform  :request="false" :lawyers="lawyerInfo.lawyers"  :lawfirmName="lawyerInfo.name" />
        </keep-alive>
      </div>
      </template>
      <div class="lawyer" v-if="lawyer_type == 'lawyer'">
        <div class="title">服务</div>
        <keep-alive>
          <lawyerServe :listServe="listServe" @consult="consultHandle"/>
        </keep-alive>
      </div>
    </main>
  </div>
</template>

<script>
import lawyerPlatform from "./components/lawyer-platform";
import lawyerServe from "./components/lawyer-serve";
import { Image } from "vant";
export default {
  data() {
    return {
      text: "",
      lawyer_type:"",
      order_type:"",
      httpUrl:"",
      lawyerId:"",
      listServe:[],//律师服务列表
      domain_nickName:[],//领域名称
      lawyerInfo:{},//律师详情
      lawfirmName:"",
      address:"",
      form:{
        avatar:"",
        status:1,
        introduction:"",
        thumb_image:"",
        address:"",
      },
      streetId:"",
      areaId:"",
      cityId:"",
      provinceId:"",
      streetName:"",
      id:""
    };
  },
  methods: {
    //服务咨询
    consultHandle({amount,consult_type,goods_id,service_day}){
      let json = {
        service_day,
        goods_id,
        l_id:this.lawyerInfo.id,
        price:amount,
        service_type:consult_type==0?1:2,
        l_name:this.lawyerInfo.name,
        lf_id:this.lawyerInfo.lf_id,
        lf_name:this.lawyerInfo.lawyer_firm.name,
        lf_province_name:this.lawyerInfo.lawyer_firm.lf_province_name,
        lf_city_name:this.lawyerInfo.lawyer_firm.lf_city_name,
        lf_area_name:this.lawyerInfo.lawyer_firm.lf_area_name,
        lf_street_name:this.lawyerInfo.lawyer_firm.lf_street_name,
        lf_address_detail:this.lawyerInfo.lawyer_firm.address_detail
      }
       $http.post("plugin.lawyer-platform.frontend.controllers.create",json).then(res => {
        if(res.result == 1){
          let order_ids = res.data.order_ids
          this.$router.push(this.fun.getUrl("orderpay",{order_ids}))
        }else{
          this.$toast(res.msg)
        }
      })
    },
    link() {
      this.text="律所详情";
      this.$router.push(this.fun.getUrl("lawyerDetail", { id:this.lawyerInfo.lf_id },{order_type:"office"}));
    },
    getData(){
      let url = this.lawyer_type == 'lawyer'?"plugin.lawyer-platform.frontend.controllers.lawyer.getDetail":"plugin.lawyer-platform.frontend.controllers.lawyer-firm.getDetail";
      $http.post(url,{id:this.id}).then(res => {
        if(res.result == 1){
          let data = res.data.detail;
          this.lawyerInfo = data;
          this.domain_nickName =  data.category_data;
          if(this.lawyer_type == 'office'){
            this.areaId =data.address.area,
            this.cityId =data.address.city,
            this.provinceId = data.address.province;
            this.form.avatar_image = data.logo_image;
            this.streetId =data.address.stree;
           let   province = JSON.parse(localStorage.getItem("province")),
              city= JSON.parse(localStorage.getItem("city")),
              area =  JSON.parse(localStorage.getItem("district")),
              provinceName = province.filter(item=>item.id==this.provinceId),
              cityName = city.filter(item=>item.id==this.cityId),
              districtName = area.filter(item=>item.id==this.areaId);
              this.address = provinceName[0].areaname + cityName[0].areaname+districtName[0].areaname;
              this.getStreet()
          }else{
            this.lawfirmName = data.lawyer_firm.name
            this.listServe = data.goods;
            this.form.avatar_image = data.avatar_image;
          }
          this.form.status = data.status;
        }
      })
    },
    getStreet() {
      $http
        .get("member.memberAddress.street", {
          district_id: this.areaId
        })
        .then(response => {
          if (response.result === 1 && !this.fun.isTextEmpty(response.data)) {
            if(this.streetId){
              response.data.forEach(item => {
                if(item.id == this.streetId){
                  this.streetName = item.areaname
                }
              })
            }
            if (!this.fun.isTextEmpty(response.data) && response.data.length > 0) {
              this.address +=this.streetName
            }
          }
        })
        .catch(error => {
          this.strShow = false;
          console.log(error);
        });
    }
  },
  activated() {
    console.log(this.$route)
    this.lawyer_type =this.$route.query.order_type;
    this.id = this.$route.params.id;
    if(this.$route.query.order_type == 'office'){
      this.text = '律所详情';
      this.httpUrl = "plugin.lawyer-platform.frontend.controllers.lawyer-firm.getLawyerList";
      this.lawyerId = this.$route.params.id;
    }else{
      this.text='律师详情';

    }
    this.getData()
  },
  components: {
    VanImage: Image,
    lawyerPlatform,
    lawyerServe
  }
};
</script>

<style lang="scss" scoped>
.office-status {
  border: 1px solid #808080;
  padding: 0.1rem 0.8rem;
  margin-top: 0.6rem;
}
.header-domain-wrapper {
  margin-top: 0.3rem;
  display: flex;
  flex-wrap: wrap;
  .header-domain-item {
    padding: 0.2rem 0.3rem;
    text-align: center;
    border-radius: 2px;
    border: 1px solid #808080;
    font-size: 0.5rem;
    margin: 0.2rem;
  }
}
.detail {
  background-color: #fff;
  .photo {
    margin-bottom: 0.5rem;
  }
  .basic-info {
    margin: 0.5rem 0;
  }
  .key {
    color: #6b6b6b;
  }
  .value {
    color: #1f1f1f;
  }
}
.title {
  color: #282828;
  margin-bottom: 0.8rem;
}
.main {
  padding: 1rem;
  .desc,
  .lawyer {
    text-align: left;
    margin-bottom: 1.8rem;
    overflow: hidden;
  }
  .desc-content {
    color: #6b6b6b;
  }
}
.header {
  display: flex;
  padding: 1rem;
  background-color: rgba(245, 211, 119, 100);
}
.header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: baseline;
  margin-left: 0.5rem;
  .header-name {
    font-size: 1rem;
  }
  .header-tel,
  .header-address {
    margin-top: 0.8rem;
    color: #3f3f3f;
    font-size: 0.8rem;
  }
}
</style>
